//
//  JingViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/8.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "JingViewController.h"


#import "MainTabBar.h"
#import "MainNavigationController.h"
#import "JingXiaoViewController.h"//经理销售动态
#import "JingOneViewController.h"//经理个人中心
#import "FenViewController.h"//营销分析
#import "HouseViewController.h"//房源管理
@interface JingViewController ()<MainTabBarDelegate>

@property(nonatomic, weak)MainTabBar *mainTabBar;
@end

@implementation JingViewController
//解决iPhone X 底部tabbar 在界面返回的时候 出现重影的问题
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    for (UIView *view in self.tabBar.subviews) {
        if (![view isKindOfClass:[MainTabBar class]]) {
            [view removeFromSuperview];
        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    MainTabBar *mainTabBar = [[MainTabBar alloc]init];
    mainTabBar.frame = self.tabBar.bounds;
    mainTabBar.delegate = self;
    [self.tabBar addSubview:mainTabBar];
    _mainTabBar =mainTabBar;
    
    NSArray *titleArr = @[@"销售动态",@"营销分析",@"房源销售",@"个人中心"];
    
    NSArray *images = @[@"tab_xiaoGrey",@"tab_yingGrey",@"tab_houseG",@"tab_mineG"];
    
    NSArray *selectedImages = @[@"tab_xiao",@"tab_ying",@"tab_house",@"tab_mine"];
    
    JingXiaoViewController *jingXiaoVC = [[JingXiaoViewController alloc] init];
    FenViewController *fenVC = [[FenViewController alloc] init];
    HouseViewController *housetVC = [[HouseViewController alloc] init];
    JingOneViewController *jingOneVC = [[JingOneViewController alloc] init];
    
    
    NSArray *viewControllers = @[jingXiaoVC,fenVC,housetVC,jingOneVC];
    
    for (int i = 0; i<viewControllers.count; i++) {
        UIViewController *childVc = viewControllers[i];
        MainNavigationController *nav = [[MainNavigationController alloc] initWithRootViewController:childVc];
        childVc.tabBarItem.image = [UIImage imageNamed:images[i]];
        childVc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImages[i]];
        childVc.tabBarItem.title = titleArr[i];
        [self.mainTabBar addTabBarButtonWithTabBarItem:childVc.tabBarItem];
        [self addChildViewController:nav];
    }
    









}

- (void)tabBar:(MainTabBar *)tabBar didSelectButtonFrom:(long)fromBtnTag to:(long)toBtnTag{
    self.selectedIndex = toBtnTag;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
